<?php
/*
 * Copyright Domenic Helfenstein
 */

function processPost() {   
   $title = $_POST['event']['title'];
   $file = $_FILES['image'];
   
   include_once ROOT_DIR.DS.'upload.php';
   $image = uploadImage($file, 100000000);
   if($image) {
      include_once ROOT_DIR.DS.'xml.php';
      insertIntoXML($_POST['event'], $image);
      return true;
   }
   
   return false;
}

if(isset($_POST['event']) && count($_POST['event'])>0) {
   if(processPost()) {
      echo '<p class="bg-success">'.$_POST['event']['title'].' wurde gespeichert</p>';
   }
}
?>
<form method="post" action="?site=add-event" enctype="multipart/form-data">
   <div class="input-group">
      <span class="input-group-addon"><span class="glyphicon glyphicon-pencil"></span></span>
      <input name="event[title]" type="text" class="form-control" placeholder="Titel" />
   </div>
   <div class="input-group">
      <span class="input-group-addon dt-button"><span class="glyphicon glyphicon-time"></span></span>
      <input name="event[begin]" type="text" class="form-control datetime" placeholder="Beginn" />
   </div>
   <div class="input-group">
      <span class="input-group-addon dt-button"><span class="glyphicon glyphicon-time"></span></span>
      <input name="event[end]" type="text" class="form-control datetime" placeholder="Ende" />
   </div>
   <div class="input-group">
      <span class="input-group-addon" style="vertical-align: top"><span class="glyphicon glyphicon-pencil"></span></span>
      <textarea name="event[description]" class="form-control" style="height: 250px" placeholder="Beschreibung" maxlength="500"></textarea>
   </div>
   <div class="input-group">
      <span class="input-group-addon"><span class="glyphicon glyphicon-picture"></span></span>
      <input name="image" type="file" accept="image/jpeg" class="form-control" title="Nach einem Bild suchen" />
   </div>
   <button type="submit" class="btn btn-success">
      <span class="glyphicon glyphicon-floppy-disk"></span> Speichern
    </button>
</form>